package com.bear.sgg.springboot_10_jap.Controller;

import com.bear.sgg.springboot_10_jap.entity.User;
import com.bear.sgg.springboot_10_jap.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassNmae UserController
 * @Description TODO
 * @Author bear
 * @Date 2020/3/16 0016 上午 11:34
 */
@RestController
public class UserController {

    @Autowired
    UserRepository userRepository;

    @GetMapping(value = "/user/{id}")
    public User getUserById(@PathVariable("id") Integer id) {
        //jpaRepository中定义了一些访问数据库的基本方式，jap底层会自定实现这些方法，我们直接调用即可
        return userRepository.findById(id).get();
    }

    @GetMapping(value = "/user/{lastName}/{email}")
    public User insertUser(User user) {
        return userRepository.save(user);
    }
}
